package cate.common.table.item.rune.row;

import cate.common.table.EExcelNoteField;
import cate.common.table.ERow;
import cate.common.table.XSSFRowWrap;
import cate.common.table.item.IBagItemTpl;
import cate.common.table.item.rune.SkillGroupList;
import cp.solution.util.str.Str;
import com.fasterxml.jackson.annotation.JsonIgnore;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;

@NoteClass(value = "徽章基础")
public class RuneBaseRow extends ERow implements IBagItemTpl {
    @NoteField(value = "下一级徽章ID")
    public int nextLevelTid;

    @NoteField(value = "幸运重铸记录ID")
    public int luckyRecastTid;

    @NoteField(value = "名称")
    public String name;

    @NoteField(value = "经验徽章")
    public boolean isExpRune;

    @NoteField(value = "堆叠上限")
    public int pileMax;

    @NoteField(value = "吞噬提供经验")
    public int baseExp;

    @NoteField(value = "是否提升技能等级")
    public boolean skillLevelUp;

    @NoteField(value = "等级加成属性组")
    public String levelAttrGroupStr;

    public String gradeUpConsumeStr;

    @NoteField(value = "重铸方式")
    public String recastTypeStr;

    @NoteField(value = "属性组")
    public String attrGroupStr;

    @NoteField(value = "等级加成属性重铸分组")
    public String levelAttrRecastGroupStr;

    @NoteField(value = "技能组")
    private String skillStr;

    @NoteField(value = "技能幸运重铸触发次数")
    public int luckyNum;

    @NoteField(value = "幸运技能组配置")
    public String luckySkillStr;

    @NoteField(value = "幸运重铸分组2")
    public String luckySkillChooseStr;

    @NoteField(value = "幸运重铸分组")
    public String luckySkillNotUseItemStr;

    @NoteField(value = "幸运重铸道具")
    public String luckyReforgeItemStr;
    @NoteField(value = "自选技能重铸道具")
    public String chooseSkillItemStr;
    @NoteField("自选属性重铸道具")
    public String chooseAttrItemStr;
    @NoteField("自选洗炼属性重铸道具")
    public String chooseGradeAttrItemStr;

    @NoteField(value = "重铸耗费")
    public String recastStr;

    @NoteField(value = "技能重铸耗费")
    public String skillRecastStr;

    @NoteField(value = "属性重铸耗费")
    public String attrRecastStr;

    @NoteField(value = "等级属性重铸耗费")
    public String gradeAttrRecastStr;

    @NoteField(value = "分解奖励")
    public String decomposeStr;

    @NoteField(value = "估值")
    public double assessValue;

    @NoteField(value = "品质")
    public int quality;

    public int levelLimit;

    @EExcelNoteField(fieldName = "永恒重铸分组1")
    public int niubiRecastGroup1;
    @EExcelNoteField(fieldName = "永恒重铸分组2")
    public int niubiRecastGroup2;
    @EExcelNoteField(fieldName = "永恒重铸道具")
    public String niubiRecastItemStr;

    @Override
    public void parse(XSSFRowWrap xr) {
        this.id = xr.getInteger("徽章类型ID", 0);
        this.nextLevelTid = xr.getInteger("下一级徽章ID", 0);
        this.luckyRecastTid = xr.getInteger("幸运重铸记录ID", 0);
        this.name = xr.getString("名称");
        this.isExpRune = xr.getBoolean("经验徽章", false);
        this.pileMax = xr.getInteger("堆叠上限", 1);
        this.baseExp = xr.getInteger("吞噬提供经验", 0);
        this.skillLevelUp = xr.getBoolean("是否提升技能等级", false);
        this.levelAttrGroupStr = xr.getString("等级加成属性组");
        this.gradeUpConsumeStr = xr.getString("强化进阶消耗");
        this.recastTypeStr = xr.getString("重铸方式");
        this.attrGroupStr = xr.getString("属性组");
        this.levelAttrRecastGroupStr = xr.getString("等级加成属性重铸分组");
        this.skillStr = xr.getString("技能组");
        this.luckyNum = xr.getInteger("技能幸运重铸触发次数", 0);
        this.luckySkillStr = xr.getString("技能幸运分组1");
        this.luckySkillChooseStr = xr.getString("幸运重铸分组2");
        this.luckyReforgeItemStr = xr.getString("幸运重铸道具");
        this.recastStr = xr.getString("重铸耗费");
        this.skillRecastStr = xr.getString("技能重铸耗费");
        this.attrRecastStr = xr.getString("属性重铸耗费");
        this.gradeAttrRecastStr = xr.getString("等级属性重铸耗费");
        this.decomposeStr = xr.getString("分解奖励");
        this.assessValue = xr.getDouble("估值", 1.0);
        this.quality = xr.getInteger("品质", 1);
        this.luckySkillNotUseItemStr = xr.getString("幸运重铸分组");
        this.levelLimit = xr.getInteger("新强化等级需求", 0);
        this.chooseSkillItemStr = xr.getString("自选技能重铸道具");
        this.chooseAttrItemStr = xr.getString("自选属性重铸道具");
        this.chooseGradeAttrItemStr = xr.getString("自选洗炼属性重铸道具");
    }

    /** 重铸方式 */
    public HashSet<Byte> recastType;

    /** 等级加成属性重铸分组 */
    public List<Integer> levelAttrRecastGroup;

    /** 属性组 */
    public List<Integer> attrGroup;
    /** 技能组 */
    @JsonIgnore
    public SkillGroupList skillGroup;
    /** 幸运技能组 */
    @JsonIgnore
    public SkillGroupList luckySkillGroup;

    public List<Integer> luckyChooseSkillGroups;

    public List<Integer> luckySkillNotUseItemGroups;

    public List<Integer> gradeAttrGroups;

    @Override
    public void decode() {
        recastType = new HashSet<>();
        if (StringUtils.isNotBlank(recastTypeStr)) {
            recastType.addAll(
                    Arrays.stream(recastTypeStr.split("#"))
                            .map(Byte::parseByte)
                            .collect(Collectors.toList()));
        }
        levelAttrRecastGroup = new ArrayList<>();
        if (StringUtils.isNotBlank(levelAttrRecastGroupStr)) {
            levelAttrRecastGroup = Str.strArr2intList(levelAttrRecastGroupStr.split(","));
        }
        attrGroup = new ArrayList<>();
        if (StringUtils.isNotBlank(attrGroupStr)) {
            attrGroup = Str.strArr2intList(attrGroupStr.split(","));
        }
        skillGroup = new SkillGroupList();
        if (StringUtils.isNotBlank(skillStr)) {
            skillGroup.parse(skillStr);
        }
        luckySkillGroup = new SkillGroupList();
        if (StringUtils.isNotBlank(luckySkillStr)) {
            luckySkillGroup.parse(luckySkillStr);
        }
        luckyChooseSkillGroups = new ArrayList<>();
        if(StringUtils.isNotBlank(luckySkillChooseStr)){
            luckyChooseSkillGroups =  Str.strArr2intList(luckySkillChooseStr.split(","));
        }
        luckySkillNotUseItemGroups = new ArrayList<>();
        if(StringUtils.isNotBlank(luckySkillNotUseItemStr)){
            luckySkillNotUseItemGroups = Str.strArr2intList(luckySkillNotUseItemStr.split(","));
        }
        gradeAttrGroups = new ArrayList<>();
        if (StringUtils.isNotBlank(levelAttrGroupStr)) {
            gradeAttrGroups = Str.strArr2intList(levelAttrGroupStr.split(","));
        }
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String toName() {
        return "徽章(品质:" + this.quality + ")";
    }

    @Override
    public boolean unique() {
        return !isExpRune;
    }

    @Override
    public int getTemplateId() {
        return id;
    }

    @Override
    public long getPileMax() {
        return pileMax;
    }
}
